#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

const int chu=1000000007;

int is_seven(long long n)
{
    if(n%7==0) return 0;
    int add=0,tmp;
    while(n/10!=0)
    {
        tmp=n%10;
        if(tmp==7) return 0;
        add +=tmp;
    }
    if(add%7==0) return 0;
    return 1;
}

int main()
{
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    int ncase;
    cin>>ncase;
    while(ncase--)
    {
        int l,r,ans=0;
        int i;
        cin>>l>>r;
        for(i=l;i<=r;i++)
        if(is_seven(i)) ans =(ans+(i%chu)*(i%chu)%chu)%chu;
        cout<<ans<<endl;
    }
    return 0;
}
